using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Reflection;
using System.IO;
using System.Text;
using EmbeddedResources1.Properties;
using System.Globalization;
using ComponentFactory.Krypton.Toolkit;
using System.Linq;
using System.Collections.Generic;

namespace EmbeddedResources1
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class MainForm : Form
    {
		private System.Windows.Forms.OpenFileDialog ofd;
        private System.Windows.Forms.SaveFileDialog sfd;
        private OpenFileDialog openFileDialogImport;
        private Ribbon ribbon1;
        private RibbonTab ribbonTab1;
        private RibbonPanel ribbonPanel1;
        private RibbonButton btnNewProject;
        private RibbonButton btnOpenProject;
        private RibbonButton btnSaveProject;
        private RibbonPanel ribbonPanel2;
        private RibbonButton ribbonButton3;
        private RibbonButton ribbonButton4;
        private ComponentFactory.Krypton.Toolkit.KryptonSplitContainer kryptonSplitContainer1;
        private ComponentFactory.Krypton.Toolkit.KryptonHeaderGroup kryptonHeaderGroup1;
        private ComponentFactory.Krypton.Toolkit.KryptonHeaderGroup kryptonHeaderGroup2;
        private ComponentFactory.Krypton.Toolkit.KryptonDataGridView kryptonDataGridView1;
        private KryptonManager kryptonManager1;
        private RibbonComboBox ribbonComboBox1;
        private RibbonSeparator ribbonSeparator1;
        private RibbonButton btnGenerateLanguage;
        private RibbonSeparator ribbonSeparator2;
        private TreeView treeView1;
        private DataGridViewTextBoxColumn assemblyNameDataGridViewTextBoxColumn;
        private DataGridViewTextBoxColumn resourceNameDataGridViewTextBoxColumn;
        private DataGridViewTextBoxColumn keyDataGridViewTextBoxColumn;
        private DataGridViewTextBoxColumn valueDataGridViewTextBoxColumn;
        private DataGridViewTextBoxColumn translatedValueDataGridViewTextBoxColumn;
        private DataGridViewTextBoxColumn languageDataGridViewTextBoxColumn;
        private BindingSource resourceKeyValueItemBindingSource;
        private BindingSource languages_LanguagesTypesBindingSource;
        private RibbonPanel ribbonPanel3;
        private RibbonButton ribbonButton1;
        private RibbonButton ribbonButton2;
        private RibbonButton ribbonButton6;
        private RibbonSeparator ribbonSeparator3;
        private IContainer components;

		public MainForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
            this.kryptonSplitContainer1 = new ComponentFactory.Krypton.Toolkit.KryptonSplitContainer();
            this.kryptonHeaderGroup1 = new ComponentFactory.Krypton.Toolkit.KryptonHeaderGroup();
            this.treeView1 = new System.Windows.Forms.TreeView();
            this.kryptonHeaderGroup2 = new ComponentFactory.Krypton.Toolkit.KryptonHeaderGroup();
            this.kryptonDataGridView1 = new ComponentFactory.Krypton.Toolkit.KryptonDataGridView();
            this.assemblyNameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.resourceNameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.keyDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.valueDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.translatedValueDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.languageDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.resourceKeyValueItemBindingSource = new System.Windows.Forms.BindingSource(this.components);
            this.ofd = new System.Windows.Forms.OpenFileDialog();
            this.sfd = new System.Windows.Forms.SaveFileDialog();
            this.openFileDialogImport = new System.Windows.Forms.OpenFileDialog();
            this.ribbon1 = new System.Windows.Forms.Ribbon();
            this.ribbonTab1 = new System.Windows.Forms.RibbonTab();
            this.ribbonPanel1 = new System.Windows.Forms.RibbonPanel();
            this.btnNewProject = new System.Windows.Forms.RibbonButton();
            this.btnOpenProject = new System.Windows.Forms.RibbonButton();
            this.btnSaveProject = new System.Windows.Forms.RibbonButton();
            this.ribbonPanel3 = new System.Windows.Forms.RibbonPanel();
            this.ribbonButton1 = new System.Windows.Forms.RibbonButton();
            this.ribbonButton2 = new System.Windows.Forms.RibbonButton();
            this.ribbonPanel2 = new System.Windows.Forms.RibbonPanel();
            this.ribbonButton6 = new System.Windows.Forms.RibbonButton();
            this.ribbonComboBox1 = new System.Windows.Forms.RibbonComboBox();
            this.ribbonSeparator2 = new System.Windows.Forms.RibbonSeparator();
            this.ribbonButton3 = new System.Windows.Forms.RibbonButton();
            this.ribbonButton4 = new System.Windows.Forms.RibbonButton();
            this.ribbonSeparator1 = new System.Windows.Forms.RibbonSeparator();
            this.btnGenerateLanguage = new System.Windows.Forms.RibbonButton();
            this.kryptonManager1 = new ComponentFactory.Krypton.Toolkit.KryptonManager(this.components);
            this.languages_LanguagesTypesBindingSource = new System.Windows.Forms.BindingSource(this.components);
            this.ribbonSeparator3 = new System.Windows.Forms.RibbonSeparator();
            ((System.ComponentModel.ISupportInitialize)(this.kryptonSplitContainer1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.kryptonSplitContainer1.Panel1)).BeginInit();
            this.kryptonSplitContainer1.Panel1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.kryptonSplitContainer1.Panel2)).BeginInit();
            this.kryptonSplitContainer1.Panel2.SuspendLayout();
            this.kryptonSplitContainer1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.kryptonHeaderGroup1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.kryptonHeaderGroup1.Panel)).BeginInit();
            this.kryptonHeaderGroup1.Panel.SuspendLayout();
            this.kryptonHeaderGroup1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.kryptonHeaderGroup2)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.kryptonHeaderGroup2.Panel)).BeginInit();
            this.kryptonHeaderGroup2.Panel.SuspendLayout();
            this.kryptonHeaderGroup2.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.kryptonDataGridView1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.resourceKeyValueItemBindingSource)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.languages_LanguagesTypesBindingSource)).BeginInit();
            this.SuspendLayout();
            // 
            // kryptonSplitContainer1
            // 
            this.kryptonSplitContainer1.Cursor = System.Windows.Forms.Cursors.Default;
            resources.ApplyResources(this.kryptonSplitContainer1, "kryptonSplitContainer1");
            this.kryptonSplitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
            this.kryptonSplitContainer1.Name = "kryptonSplitContainer1";
            // 
            // kryptonSplitContainer1.Panel1
            // 
            this.kryptonSplitContainer1.Panel1.Controls.Add(this.kryptonHeaderGroup1);
            // 
            // kryptonSplitContainer1.Panel2
            // 
            this.kryptonSplitContainer1.Panel2.Controls.Add(this.kryptonHeaderGroup2);
            // 
            // kryptonHeaderGroup1
            // 
            resources.ApplyResources(this.kryptonHeaderGroup1, "kryptonHeaderGroup1");
            this.kryptonHeaderGroup1.Name = "kryptonHeaderGroup1";
            // 
            // kryptonHeaderGroup1.Panel
            // 
            this.kryptonHeaderGroup1.Panel.Controls.Add(this.treeView1);
            this.kryptonHeaderGroup1.ValuesPrimary.Description = resources.GetString("kryptonHeaderGroup1.ValuesPrimary.Description");
            this.kryptonHeaderGroup1.ValuesPrimary.Heading = resources.GetString("kryptonHeaderGroup1.ValuesPrimary.Heading");
            this.kryptonHeaderGroup1.ValuesPrimary.Image = global::EmbeddedResources1.Properties.Resources.view_choose;
            this.kryptonHeaderGroup1.ValuesSecondary.Description = resources.GetString("kryptonHeaderGroup1.ValuesSecondary.Description");
            this.kryptonHeaderGroup1.ValuesSecondary.Heading = resources.GetString("kryptonHeaderGroup1.ValuesSecondary.Heading");
            this.kryptonHeaderGroup1.ValuesSecondary.Image = null;
            // 
            // treeView1
            // 
            resources.ApplyResources(this.treeView1, "treeView1");
            this.treeView1.Name = "treeView1";
            this.treeView1.DoubleClick += new System.EventHandler(this.treeView1_DoubleClick);
            // 
            // kryptonHeaderGroup2
            // 
            resources.ApplyResources(this.kryptonHeaderGroup2, "kryptonHeaderGroup2");
            this.kryptonHeaderGroup2.Name = "kryptonHeaderGroup2";
            // 
            // kryptonHeaderGroup2.Panel
            // 
            this.kryptonHeaderGroup2.Panel.Controls.Add(this.kryptonDataGridView1);
            this.kryptonHeaderGroup2.ValuesPrimary.Description = resources.GetString("kryptonHeaderGroup2.ValuesPrimary.Description");
            this.kryptonHeaderGroup2.ValuesPrimary.Heading = resources.GetString("kryptonHeaderGroup2.ValuesPrimary.Heading");
            this.kryptonHeaderGroup2.ValuesPrimary.Image = global::EmbeddedResources1.Properties.Resources.locale;
            this.kryptonHeaderGroup2.ValuesSecondary.Description = resources.GetString("kryptonHeaderGroup2.ValuesSecondary.Description");
            this.kryptonHeaderGroup2.ValuesSecondary.Heading = resources.GetString("kryptonHeaderGroup2.ValuesSecondary.Heading");
            this.kryptonHeaderGroup2.ValuesSecondary.Image = null;
            // 
            // kryptonDataGridView1
            // 
            this.kryptonDataGridView1.AllowUserToAddRows = false;
            this.kryptonDataGridView1.AllowUserToDeleteRows = false;
            this.kryptonDataGridView1.AutoGenerateColumns = false;
            this.kryptonDataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.kryptonDataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.assemblyNameDataGridViewTextBoxColumn,
            this.resourceNameDataGridViewTextBoxColumn,
            this.keyDataGridViewTextBoxColumn,
            this.valueDataGridViewTextBoxColumn,
            this.translatedValueDataGridViewTextBoxColumn,
            this.languageDataGridViewTextBoxColumn});
            this.kryptonDataGridView1.DataSource = this.resourceKeyValueItemBindingSource;
            resources.ApplyResources(this.kryptonDataGridView1, "kryptonDataGridView1");
            this.kryptonDataGridView1.Name = "kryptonDataGridView1";
            this.kryptonDataGridView1.RowHeadersVisible = false;
            this.kryptonDataGridView1.StateCommon.BackStyle = ComponentFactory.Krypton.Toolkit.PaletteBackStyle.GridBackgroundList;
            // 
            // assemblyNameDataGridViewTextBoxColumn
            // 
            this.assemblyNameDataGridViewTextBoxColumn.DataPropertyName = "AssemblyName";
            resources.ApplyResources(this.assemblyNameDataGridViewTextBoxColumn, "assemblyNameDataGridViewTextBoxColumn");
            this.assemblyNameDataGridViewTextBoxColumn.Name = "assemblyNameDataGridViewTextBoxColumn";
            // 
            // resourceNameDataGridViewTextBoxColumn
            // 
            this.resourceNameDataGridViewTextBoxColumn.DataPropertyName = "ResourceName";
            resources.ApplyResources(this.resourceNameDataGridViewTextBoxColumn, "resourceNameDataGridViewTextBoxColumn");
            this.resourceNameDataGridViewTextBoxColumn.Name = "resourceNameDataGridViewTextBoxColumn";
            // 
            // keyDataGridViewTextBoxColumn
            // 
            this.keyDataGridViewTextBoxColumn.DataPropertyName = "Key";
            resources.ApplyResources(this.keyDataGridViewTextBoxColumn, "keyDataGridViewTextBoxColumn");
            this.keyDataGridViewTextBoxColumn.Name = "keyDataGridViewTextBoxColumn";
            // 
            // valueDataGridViewTextBoxColumn
            // 
            this.valueDataGridViewTextBoxColumn.DataPropertyName = "Value";
            resources.ApplyResources(this.valueDataGridViewTextBoxColumn, "valueDataGridViewTextBoxColumn");
            this.valueDataGridViewTextBoxColumn.Name = "valueDataGridViewTextBoxColumn";
            // 
            // translatedValueDataGridViewTextBoxColumn
            // 
            this.translatedValueDataGridViewTextBoxColumn.DataPropertyName = "TranslatedValue";
            resources.ApplyResources(this.translatedValueDataGridViewTextBoxColumn, "translatedValueDataGridViewTextBoxColumn");
            this.translatedValueDataGridViewTextBoxColumn.Name = "translatedValueDataGridViewTextBoxColumn";
            // 
            // languageDataGridViewTextBoxColumn
            // 
            this.languageDataGridViewTextBoxColumn.DataPropertyName = "Language";
            resources.ApplyResources(this.languageDataGridViewTextBoxColumn, "languageDataGridViewTextBoxColumn");
            this.languageDataGridViewTextBoxColumn.Name = "languageDataGridViewTextBoxColumn";
            // 
            // resourceKeyValueItemBindingSource
            // 
            this.resourceKeyValueItemBindingSource.DataSource = typeof(EmbeddedResources1.ResourceKeyValueItem);
            // 
            // ofd
            // 
            this.ofd.DefaultExt = "dll";
            resources.ApplyResources(this.ofd, "ofd");
            // 
            // sfd
            // 
            resources.ApplyResources(this.sfd, "sfd");
            // 
            // openFileDialogImport
            // 
            resources.ApplyResources(this.openFileDialogImport, "openFileDialogImport");
            // 
            // ribbon1
            // 
            resources.ApplyResources(this.ribbon1, "ribbon1");
            this.ribbon1.Minimized = false;
            this.ribbon1.Name = "ribbon1";
            this.ribbon1.Tabs.Add(this.ribbonTab1);
            this.ribbon1.TabsColapsed = false;
            this.ribbon1.TabSpacing = 6;
            // 
            // ribbonTab1
            // 
            this.ribbonTab1.Panels.Add(this.ribbonPanel1);
            this.ribbonTab1.Panels.Add(this.ribbonPanel3);
            this.ribbonTab1.Panels.Add(this.ribbonPanel2);
            this.ribbonTab1.Tag = null;
            resources.ApplyResources(this.ribbonTab1, "ribbonTab1");
            // 
            // ribbonPanel1
            // 
            this.ribbonPanel1.Enabled = false;
            this.ribbonPanel1.Items.Add(this.btnNewProject);
            this.ribbonPanel1.Items.Add(this.btnOpenProject);
            this.ribbonPanel1.Items.Add(this.btnSaveProject);
            this.ribbonPanel1.Tag = null;
            resources.ApplyResources(this.ribbonPanel1, "ribbonPanel1");
            // 
            // btnNewProject
            // 
            this.btnNewProject.AltKey = null;
            this.btnNewProject.DropDownArrowSize = new System.Drawing.Size(5, 3);
            this.btnNewProject.Enabled = false;
            this.btnNewProject.Image = global::EmbeddedResources1.Properties.Resources.filenew;
            this.btnNewProject.SmallImage = ((System.Drawing.Image)(resources.GetObject("btnNewProject.SmallImage")));
            this.btnNewProject.Style = System.Windows.Forms.RibbonButtonStyle.Normal;
            this.btnNewProject.Tag = null;
            resources.ApplyResources(this.btnNewProject, "btnNewProject");
            this.btnNewProject.ToolTip = null;
            this.btnNewProject.ToolTipImage = null;
            this.btnNewProject.ToolTipTitle = null;
            // 
            // btnOpenProject
            // 
            this.btnOpenProject.AltKey = null;
            this.btnOpenProject.DropDownArrowSize = new System.Drawing.Size(5, 3);
            this.btnOpenProject.Enabled = false;
            this.btnOpenProject.Image = global::EmbeddedResources1.Properties.Resources.fileopen;
            this.btnOpenProject.SmallImage = ((System.Drawing.Image)(resources.GetObject("btnOpenProject.SmallImage")));
            this.btnOpenProject.Style = System.Windows.Forms.RibbonButtonStyle.Normal;
            this.btnOpenProject.Tag = null;
            resources.ApplyResources(this.btnOpenProject, "btnOpenProject");
            this.btnOpenProject.ToolTip = null;
            this.btnOpenProject.ToolTipImage = null;
            this.btnOpenProject.ToolTipTitle = null;
            // 
            // btnSaveProject
            // 
            this.btnSaveProject.AltKey = null;
            this.btnSaveProject.DropDownArrowSize = new System.Drawing.Size(5, 3);
            this.btnSaveProject.Enabled = false;
            this.btnSaveProject.Image = global::EmbeddedResources1.Properties.Resources.filesave;
            this.btnSaveProject.SmallImage = ((System.Drawing.Image)(resources.GetObject("btnSaveProject.SmallImage")));
            this.btnSaveProject.Style = System.Windows.Forms.RibbonButtonStyle.Normal;
            this.btnSaveProject.Tag = null;
            resources.ApplyResources(this.btnSaveProject, "btnSaveProject");
            this.btnSaveProject.ToolTip = null;
            this.btnSaveProject.ToolTipImage = null;
            this.btnSaveProject.ToolTipTitle = null;
            // 
            // ribbonPanel3
            // 
            this.ribbonPanel3.Items.Add(this.ribbonButton1);
            this.ribbonPanel3.Items.Add(this.ribbonButton2);
            this.ribbonPanel3.Tag = null;
            resources.ApplyResources(this.ribbonPanel3, "ribbonPanel3");
            // 
            // ribbonButton1
            // 
            this.ribbonButton1.AltKey = null;
            this.ribbonButton1.DropDownArrowSize = new System.Drawing.Size(5, 3);
            this.ribbonButton1.Image = global::EmbeddedResources1.Properties.Resources.tab_new;
            this.ribbonButton1.SmallImage = ((System.Drawing.Image)(resources.GetObject("ribbonButton1.SmallImage")));
            this.ribbonButton1.Style = System.Windows.Forms.RibbonButtonStyle.Normal;
            this.ribbonButton1.Tag = null;
            resources.ApplyResources(this.ribbonButton1, "ribbonButton1");
            this.ribbonButton1.ToolTip = null;
            this.ribbonButton1.ToolTipImage = null;
            this.ribbonButton1.ToolTipTitle = null;
            this.ribbonButton1.Click += new System.EventHandler(this.loadAssembly_Click);
            // 
            // ribbonButton2
            // 
            this.ribbonButton2.AltKey = null;
            this.ribbonButton2.DropDownArrowSize = new System.Drawing.Size(5, 3);
            this.ribbonButton2.Image = global::EmbeddedResources1.Properties.Resources.tab_remove;
            this.ribbonButton2.SmallImage = ((System.Drawing.Image)(resources.GetObject("ribbonButton2.SmallImage")));
            this.ribbonButton2.Style = System.Windows.Forms.RibbonButtonStyle.Normal;
            this.ribbonButton2.Tag = null;
            resources.ApplyResources(this.ribbonButton2, "ribbonButton2");
            this.ribbonButton2.ToolTip = null;
            this.ribbonButton2.ToolTipImage = null;
            this.ribbonButton2.ToolTipTitle = null;
            this.ribbonButton2.Click += new System.EventHandler(this.ribbonButton2_Click);
            // 
            // ribbonPanel2
            // 
            this.ribbonPanel2.Items.Add(this.ribbonComboBox1);
            this.ribbonPanel2.Items.Add(this.ribbonSeparator2);
            this.ribbonPanel2.Items.Add(this.ribbonButton6);
            this.ribbonPanel2.Items.Add(this.ribbonSeparator3);
            this.ribbonPanel2.Items.Add(this.ribbonButton3);
            this.ribbonPanel2.Items.Add(this.ribbonButton4);
            this.ribbonPanel2.Items.Add(this.ribbonSeparator1);
            this.ribbonPanel2.Items.Add(this.btnGenerateLanguage);
            this.ribbonPanel2.Tag = null;
            resources.ApplyResources(this.ribbonPanel2, "ribbonPanel2");
            // 
            // ribbonButton6
            // 
            this.ribbonButton6.AltKey = null;
            this.ribbonButton6.DropDownArrowSize = new System.Drawing.Size(5, 3);
            this.ribbonButton6.Image = global::EmbeddedResources1.Properties.Resources.locale1;
            this.ribbonButton6.SmallImage = ((System.Drawing.Image)(resources.GetObject("ribbonButton6.SmallImage")));
            this.ribbonButton6.Style = System.Windows.Forms.RibbonButtonStyle.Normal;
            this.ribbonButton6.Tag = null;
            resources.ApplyResources(this.ribbonButton6, "ribbonButton6");
            this.ribbonButton6.ToolTip = null;
            this.ribbonButton6.ToolTipImage = null;
            this.ribbonButton6.ToolTipTitle = null;
            this.ribbonButton6.Click += new System.EventHandler(this.ribbonButton6_Click);
            // 
            // ribbonComboBox1
            // 
            this.ribbonComboBox1.AltKey = null;
            this.ribbonComboBox1.Image = null;
            this.ribbonComboBox1.Tag = null;
            resources.ApplyResources(this.ribbonComboBox1, "ribbonComboBox1");
            this.ribbonComboBox1.TextBoxText = "";
            this.ribbonComboBox1.ToolTip = null;
            this.ribbonComboBox1.ToolTipImage = null;
            this.ribbonComboBox1.ToolTipTitle = null;
            this.ribbonComboBox1.TextBoxTextChanged += new System.EventHandler(this.ribbonComboBox1_TextBoxTextChanged);
            // 
            // ribbonSeparator2
            // 
            this.ribbonSeparator2.AltKey = null;
            this.ribbonSeparator2.Image = null;
            this.ribbonSeparator2.Tag = null;
            this.ribbonSeparator2.Text = null;
            this.ribbonSeparator2.ToolTip = null;
            this.ribbonSeparator2.ToolTipImage = null;
            this.ribbonSeparator2.ToolTipTitle = null;
            // 
            // ribbonButton3
            // 
            this.ribbonButton3.AltKey = null;
            this.ribbonButton3.DropDownArrowSize = new System.Drawing.Size(5, 3);
            this.ribbonButton3.Image = global::EmbeddedResources1.Properties.Resources.spreadsheet;
            this.ribbonButton3.SmallImage = ((System.Drawing.Image)(resources.GetObject("ribbonButton3.SmallImage")));
            this.ribbonButton3.Style = System.Windows.Forms.RibbonButtonStyle.Normal;
            this.ribbonButton3.Tag = null;
            resources.ApplyResources(this.ribbonButton3, "ribbonButton3");
            this.ribbonButton3.ToolTip = null;
            this.ribbonButton3.ToolTipImage = null;
            this.ribbonButton3.ToolTipTitle = null;
            this.ribbonButton3.Click += new System.EventHandler(this.ribbonButton3_Click);
            // 
            // ribbonButton4
            // 
            this.ribbonButton4.AltKey = null;
            this.ribbonButton4.DropDownArrowSize = new System.Drawing.Size(5, 3);
            this.ribbonButton4.Image = global::EmbeddedResources1.Properties.Resources.compfile;
            this.ribbonButton4.SmallImage = ((System.Drawing.Image)(resources.GetObject("ribbonButton4.SmallImage")));
            this.ribbonButton4.Style = System.Windows.Forms.RibbonButtonStyle.Normal;
            this.ribbonButton4.Tag = null;
            resources.ApplyResources(this.ribbonButton4, "ribbonButton4");
            this.ribbonButton4.ToolTip = null;
            this.ribbonButton4.ToolTipImage = null;
            this.ribbonButton4.ToolTipTitle = null;
            this.ribbonButton4.Click += new System.EventHandler(this.btnReadFromCVS_Click);
            // 
            // ribbonSeparator1
            // 
            this.ribbonSeparator1.AltKey = null;
            this.ribbonSeparator1.Image = null;
            this.ribbonSeparator1.Tag = null;
            this.ribbonSeparator1.Text = null;
            this.ribbonSeparator1.ToolTip = null;
            this.ribbonSeparator1.ToolTipImage = null;
            this.ribbonSeparator1.ToolTipTitle = null;
            // 
            // btnGenerateLanguage
            // 
            this.btnGenerateLanguage.AltKey = null;
            this.btnGenerateLanguage.DropDownArrowSize = new System.Drawing.Size(5, 3);
            this.btnGenerateLanguage.Image = global::EmbeddedResources1.Properties.Resources.wizard;
            this.btnGenerateLanguage.SmallImage = ((System.Drawing.Image)(resources.GetObject("btnGenerateLanguage.SmallImage")));
            this.btnGenerateLanguage.Style = System.Windows.Forms.RibbonButtonStyle.Normal;
            this.btnGenerateLanguage.Tag = null;
            resources.ApplyResources(this.btnGenerateLanguage, "btnGenerateLanguage");
            this.btnGenerateLanguage.ToolTip = null;
            this.btnGenerateLanguage.ToolTipImage = null;
            this.btnGenerateLanguage.ToolTipTitle = null;
            this.btnGenerateLanguage.Click += new System.EventHandler(this.btnGenerateLanguage_Click);
            // 
            // kryptonManager1
            // 
            this.kryptonManager1.GlobalPaletteMode = ComponentFactory.Krypton.Toolkit.PaletteModeManager.Office2007Silver;
            // 
            // languages_LanguagesTypesBindingSource
            // 
            this.languages_LanguagesTypesBindingSource.DataSource = typeof(EmbeddedResources1.Languages.LanguagesTypes);
            // 
            // ribbonSeparator3
            // 
            this.ribbonSeparator3.AltKey = null;
            this.ribbonSeparator3.Image = null;
            this.ribbonSeparator3.Tag = null;
            this.ribbonSeparator3.Text = null;
            this.ribbonSeparator3.ToolTip = null;
            this.ribbonSeparator3.ToolTipImage = null;
            this.ribbonSeparator3.ToolTipTitle = null;
            // 
            // MainForm
            // 
            resources.ApplyResources(this, "$this");
            this.Controls.Add(this.kryptonSplitContainer1);
            this.Controls.Add(this.ribbon1);
            this.Name = "MainForm";
            this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            this.Load += new System.EventHandler(this.MainForm_Load);
            ((System.ComponentModel.ISupportInitialize)(this.kryptonSplitContainer1.Panel1)).EndInit();
            this.kryptonSplitContainer1.Panel1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.kryptonSplitContainer1.Panel2)).EndInit();
            this.kryptonSplitContainer1.Panel2.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.kryptonSplitContainer1)).EndInit();
            this.kryptonSplitContainer1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.kryptonHeaderGroup1.Panel)).EndInit();
            this.kryptonHeaderGroup1.Panel.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.kryptonHeaderGroup1)).EndInit();
            this.kryptonHeaderGroup1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.kryptonHeaderGroup2.Panel)).EndInit();
            this.kryptonHeaderGroup2.Panel.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.kryptonHeaderGroup2)).EndInit();
            this.kryptonHeaderGroup2.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.kryptonDataGridView1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.resourceKeyValueItemBindingSource)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.languages_LanguagesTypesBindingSource)).EndInit();
            this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
          //  System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");
            string a = Resources.String1;
			Application.Run(new MainForm());
            
		}

		private void loadAssembly_Click(object sender, System.EventArgs e)
		{
/*            if (treeView1.Nodes.Count != 0)
            {
                treeView1.Nodes.Clear();
                Project.AllResources.Clear();
                Project.Assemblies.Clear();
            }*/
  
			ofd.FileName = "";
            ofd.Multiselect = true;
			if( ofd.ShowDialog() == DialogResult.Cancel )
				return;

            foreach (String file in ofd.FileNames)
            {
                try
                {
                    if (file.ToLower().Contains(".resources."))
                    {
                        MessageBox.Show("This is a localized assembly. Please choose the main assembly before this.");
                    }
                    else
                    {
                        LoadResources(Assembly.LoadFrom(file),Languages.LanguagesTypes.DEFAULT);
                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            SetDataGridResourcesToLanguage(Languages.LanguagesTypes.DEFAULT);
		}

		private void LoadResources(Assembly loadedAssembly, Languages.LanguagesTypes language)
		{
            if (Project.Assemblies.Contains(loadedAssembly.FullName))
                throw new ApplicationException("Assembly already loaded.");

			string [] resourceNames = loadedAssembly.GetManifestResourceNames();

			if( resourceNames.Length > 0 )
			{
                TreeNode node = treeView1.Nodes.Add(loadedAssembly.GetName().Name, loadedAssembly.GetName().Name);

				foreach(string resourceName in resourceNames)
				{
                    node.Nodes.Add(resourceName);
                    LoadResourcesFromAssembly(loadedAssembly, resourceName, language);
				}

                Project.Assemblies.Add(loadedAssembly.FullName.Split(',')[0]);
            }
		}

        private void LoadResourcesFromAssembly(Assembly loadedAssembly, string resName, Languages.LanguagesTypes language)
        {
            Stream inFile = loadedAssembly.GetManifestResourceStream(resName);

            ManifestResourceInfo resInfo = loadedAssembly.GetManifestResourceInfo(resName);
            try
            {
                int resNum = 0;
                System.Resources.ResourceReader resReader = new System.Resources.ResourceReader(inFile);
                IDictionaryEnumerator dictEnum = resReader.GetEnumerator();
                while (dictEnum.MoveNext() == true)
                {
                    if (dictEnum.Key is string && dictEnum.Value is string)
                    {
                        string resKey = (string)dictEnum.Key;
                        string resValue = (string)dictEnum.Value;
                        if (resKey.Contains(".Text") 
                            || resKey.Contains(".HeaderText") 
                            || resName.Contains(".Properties.Resources.") 
                            || resKey.Contains(".Heading")
                            || resKey.Contains("Description")
                            || resKey.Contains("Title"))
                        {
                            ResourceKeyValueItem resourceKey = new ResourceKeyValueItem();
                            resourceKey.Key = resKey;
                            resourceKey.AssemblyName = loadedAssembly.FullName.Split(',')[0];
                            resourceKey.ResourceName = resName;
                            resourceKey.Value = resValue;
                            resourceKey.Language = language;
                            if (Project.AllResources.Where<ResourceKeyValueItem>(res => res.Equals(resourceKey)).Count<ResourceKeyValueItem>() > 0)
                            {
                            }
                            else
                            {
                                Project.AllResources.Add(resourceKey);
                                resNum++;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            inFile.Close();
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        public LocalizationProject Project = new LocalizationProject();
        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
          
        }

        private void btnReadFromCVS_Click(object sender, EventArgs e)
        {
            if (this.openFileDialogImport.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    string[] TranslatedLines = System.IO.File.ReadAllLines(this.openFileDialogImport.FileName, Encoding.UTF7);

                    IList<ResourceKeyValueItem> readResources = new List<ResourceKeyValueItem>();
                    foreach (String CurrLine in TranslatedLines)
                    {
                        String[] splitter = new String[2];
                        splitter[0] = ";";
                        splitter[1] = "\t";
                        String[] LineValues = CurrLine.Split(splitter, StringSplitOptions.None);
                        String Assembly = LineValues[0];
                        String ResoureItemName = LineValues[1];
                        String Key = LineValues[2];
                        String Value = LineValues[3];
                        String TranslatedValue = LineValues[4];
                        String Language = LineValues[5];

                        ResourceKeyValueItem res = new ResourceKeyValueItem();
                        res.Key = Key;
                        res.Language = Languages.GetLanguage(Language);
                        res.ResourceName = ResoureItemName;
                        res.AssemblyName = Assembly;
                        res.Value = Value;
                        res.TranslatedValue = TranslatedValue;

                        readResources.Add(res);
                    }

                    MergeReadResourcesInProject(readResources);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Erro ao importar o ficheiro. Valide o formato.");
                }

                //Refresh the data in datagrid
                Languages.LanguagesTypes lang = Languages.GetLanguage(ribbonComboBox1.TextBoxText);
                SetDataGridResourcesToLanguage(lang);
            }
        }


        private void MergeReadResourcesInProject(IList<ResourceKeyValueItem> list)
        {
            foreach (ResourceKeyValueItem item in list)
            {

                try
                {
                    ResourceKeyValueItem original = Project.AllResources.Where(res => res.AssemblyName == item.AssemblyName &&
                                                      res.ResourceName == item.ResourceName &&
                                                      res.Key == item.Key &&
                                                      res.Language == item.Language).Single();
                    if (original == null)
                    {
                        Project.AllResources.Add(item);
                    }
                    else
                    {
                        original.TranslatedValue = item.TranslatedValue;
                    }
                }
                catch (Exception ex)
                {
                    Project.AllResources.Add(item);
                }


            }

        }

        private void buttonSpecHeaderGroup1_Click(object sender, EventArgs e)
        {
            loadAssembly_Click(sender, e);

        }

        private void ribbonComboBox1_TextBoxTextChanged(object sender, EventArgs e)
        {

        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            foreach (String str in Languages.GetAllLanguageStrings())
            {
                RibbonButton rb = new RibbonButton(str);
                rb.Click += new EventHandler(rb_Click);
                ribbonComboBox1.DropDownItems.Add(rb);
            }
        }

        private void SetDataGridResourcesToLanguage(Languages.LanguagesTypes language)
        {
            this.resourceKeyValueItemBindingSource.DataSource = Project.AllResources.Where<ResourceKeyValueItem>(res => res.Language == language);
            if (language == Languages.LanguagesTypes.DEFAULT)
            {
                this.kryptonDataGridView1.ReadOnly = true;
            }
            else
            {
                this.kryptonDataGridView1.ReadOnly = false;
            }
        }

        void rb_Click(object sender, EventArgs e)
        {
            if (sender is RibbonButton)
            {

                Languages.LanguagesTypes lang = Languages.GetLanguage(((RibbonButton)sender).Text);

                if (Project.IsLanguageDefined(lang) == false)
                {
                    //Criar Todos os Items para esta Linguagem
                    IList<ResourceKeyValueItem> defaultLanguages = Project.AllResources.Where<ResourceKeyValueItem>(res => res.Language == Languages.LanguagesTypes.DEFAULT).ToList<ResourceKeyValueItem>();
                    foreach (ResourceKeyValueItem res in defaultLanguages)
                    {
                        ResourceKeyValueItem newResource = (ResourceKeyValueItem)res.Clone();
                        newResource.Language = lang;
                        Project.AllResources.Add(newResource);
                    }
                }
                SetDataGridResourcesToLanguage(lang);
            }
        }

        private void buttonSpecHeaderGroup3_Click(object sender, EventArgs e)
        {

            Languages.LanguagesTypes lang = Languages.GetLanguage(ribbonComboBox1.TextBoxText);
            if (lang == Languages.LanguagesTypes.DEFAULT)
            {
                MessageBox.Show("Please choose the assembly language first.");
                return;
            }

            ofd.FileName = "";
            ofd.Multiselect = true;
            ofd.Filter = "Localized Assemblyes|*.resources.dll|All Files|*.*";
            if (ofd.ShowDialog() == DialogResult.Cancel)
                return;

            foreach (String file in ofd.FileNames)
            {
                try
                {
                        //this.LoadResourcesFromAssembly(Assembly.LoadFrom(file), lang);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            SetDataGridResourcesToLanguage(lang);

        }

        private void buttonSpecHeaderGroup2_Click(object sender, EventArgs e)
        {
            MessageBox.Show ("Remove Assembly. Not Implemented Yet.");
        }

        private void ribbonButton3_Click(object sender, EventArgs e)
        {
            Project.ExportLanguageToCSV(Languages.GetLanguage(ribbonComboBox1.TextBoxText));
            MessageBox.Show("Language Exported to CSV.","Information",MessageBoxButtons.OK,MessageBoxIcon.Information);
        }

        private void btnGenerateLanguage_Click(object sender, EventArgs e)
        {
            Project.ExportLanguage(Languages.GetLanguage(ribbonComboBox1.TextBoxText));
            MessageBox.Show("Language DLLs Generated.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void ribbonButton2_Click(object sender, EventArgs e)
        {
            TreeNode node = treeView1.SelectedNode;

            if (node != null && Project.Assemblies.Contains(node.Name))
            {
                DialogResult res= MessageBox.Show("Remove all resources in Assembly: " + node.Name + "?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (res == DialogResult.Yes)
                {
                    Project.RemoveResourcesByAssembly(node.Name);
                    Languages.LanguagesTypes lang = Languages.GetLanguage(ribbonComboBox1.TextBoxText);
                    SetDataGridResourcesToLanguage(lang);
                    this.treeView1.Nodes.Remove(node);
                }
            }

        }

        private void treeView1_DoubleClick(object sender, EventArgs e)
        {
            TreeNode node = treeView1.SelectedNode;
            if (node != null)
            {
                if (Project.Assemblies.Contains(node.Name))
                {
                    Languages.LanguagesTypes lang = Languages.GetLanguage(ribbonComboBox1.TextBoxText);
                    this.resourceKeyValueItemBindingSource.DataSource = Project.AllResources.Where(res => res.AssemblyName == node.Name && res.Language == lang).ToList<ResourceKeyValueItem>();
                }
                else
                {
                    TreeNode parent = node.Parent;
                    Languages.LanguagesTypes lang = Languages.GetLanguage(ribbonComboBox1.TextBoxText);
                    this.resourceKeyValueItemBindingSource.DataSource = Project.AllResources.Where(res => res.AssemblyName == parent.Name && res.ResourceName == node.Text && res.Language == lang).ToList<ResourceKeyValueItem>();

                }
            }
        }

        private void ribbonButton6_Click(object sender, EventArgs e)
        {
            buttonSpecHeaderGroup3_Click(sender, e);
        }

	}
}
